package cn.bjtu.archiprac.papercheck.application.model;

import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Zexin Lin on 4/13/2018.
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Pagination<T> {
    private List<T> list;
    private Integer totalCount;
    private Integer pageIndex;
    private Integer pageSize;

    public Pagination() {
    }

    public Pagination(Integer pageIndex, Integer pageSize) {
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(T obj) {
        List<T> newList = new ArrayList<T>();
        newList.add(obj);
        this.setList(newList);
    }

    public void setList(List<T> data) {
        this.list = data;
        totalCount = this.list.size();
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(Integer pageIndex) {
        this.pageIndex = pageIndex;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    @Override
    public String toString() {
        return "{" +
                "totalCount=" + totalCount +
                ", pageIndex=" + pageIndex +
                ", pageSize=" + pageSize +
                '}';
    }
}
